package xin.mashibo.pattern.visitor;

import xin.mashibo.pattern.composite.FileTreatMentException;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 文件目录类
 *
 * @author MaShibo
 * 日期 :  2019/1/24
 */
public class Directory extends Entry {

    private String name;

    private List<Entry> dir = new ArrayList<>();


    public Directory(String name) {
        this.name = name;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public int getSize() {
        int size = 0;
        for (Entry entry : dir) {
            size += entry.getSize();
        }
        return size;
    }

    @Override
    public void accept(Visitor visitor) {
        visitor.visit(this);
    }


    @Override
    public Entry add(Entry entry) throws FileTreatMentException {
        dir.add(entry);
        return this;
    }

    @Override
    public Iterator<Entry> iterator() throws FileTreatMentException {
        return dir.iterator();
    }
}
